import Http from "../utils/Http";
import constant from "../config/constant";

export default class CityModel extends Http {

  tree() {
    return this.request({
      url: '/h5/city/tree'
    })
  }

  edit(data) {
    return this.request({
      url: '/h5/execute/address/edit',
      data
    })
  }

  list(data) {
    return this.request({
      url: '/h5/execute/address/list',
      data
    })
  }

  remove(data) {
    return this.request({
      url: '/h5/execute/address/delete',
      data
    })
  }

  getTree() {
    return new Promise(resolve => {
      const key = constant.address
      let tree = wx.getStorageSync(key)
      if (!tree) {
        this.tree().then(response => {
          tree = response.data.tree
          resolve(tree)
        })
      } else {
        resolve(tree)
      }
    })
  }

  view(data) {
    return this.request({
      url: '/h5/execute/address/view',
      data
    })
  }

}
